﻿
using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;
using YouHP.Model.Group;

namespace YouHP.Pages.BBS
{
    public class TopicDel:TopicBasePage
    {
        

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();
        }

      
        protected void HandleCommon()
        {

            if (UserData.Id <= 0)
            {
                this.AddErrLine("您还没有登录，请点击先登录！");
                this.MsgboxUrl = this.GetUrl("/User/Login.aspx");
                return;
            }
            //判断是否有权限
            if (!CanDel())
            {
                this.AddErrLine("你没有权限操作！");
                return;
            }

            bool succ = TopicBLL.Instance.DeleteTopic(GroupData.Id,TopicData.Id,TopicData.PostUserId);

            if (succ)
            {
                this.Redirect("/BBS/Board.aspx?gid=" + GroupData.Id);
            }
            else
            {
                this.AddErrLine("操作失败！");
                return;
            }
        }

        protected bool CanDel()
        {
            bool retVal = false;
            if (UserData.Id == TopicData.PostUserId)
            {
                retVal = true;
            }
            for (int i = 0; i < moderatorsId.Length; i++)
            {
                if (UserData.Id == moderatorsId[i])
                {
                    retVal = true;
                    break;
                }
            }
            return retVal;
        }

    }
}